<template>
	<view class="">
		<u-sticky bgColor="#fff">
			<u-tabs :list="tabs" lineColor="#fe8604" :activeStyle="{
			    color: '#333',
			    fontWeight: 'bold',
			    transform: 'scale(1.05)',
				fontSize:'30rpx'
			}" :inactiveStyle="{
			    color: '#999',
			    transform: 'scale(1)',
				fontSize:'30rpx'
			}" keyName="name":scrollable="false"  @click="tabclick"></u-tabs>
		</u-sticky>
		<view class="mainpadding2">
			<view class="flexcolumn" v-if="list.data.length==0">
				<view class="placeholderimage" style="margin-top: 200rpx;"></view>
				<view class="xiaohui margin_top main_size">暂无数据</view>
			</view>
			<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id" @click="jumpdetail('/pages_mypage/dingdanxq?id=',item.id)">
				<view class="flexbetween">
					<view class="xiaohei titletext bold">订单编号：{{item.order_no}}</view>
					<!-- 订单状态:1=待支付,3=待核销,6=已完成,7=已取消-->
					<view class="xiaohuang main_size" v-if="item.state==1">待支付</view>
					<view class="xiaohuang main_size" v-if="item.state==3">待核销</view>
					<view class="xiaolv main_size" v-if="item.state==6">已完成</view>
					<view class="xiaohui main_size" v-if="item.state==7">已取消</view>
					
				</view>
				<view class="flexleft margin_top xiahuaxian" v-for="ite in item.goods" :key="ite.id">
					<image :src="ite.image_text" class="listleftimg3 margin_right" mode=""></image>
					<view class="flexcolumnbet" style="height: 140rpx;width: 100%;">
						<view class="main_size xiaohei lianghang">{{ite.title}}</view>
						<view class="flexbetween" style="width: 100%;">
							<view class="main_size xiaohuang bold">{{ite.price}}</view>
							<view class="xiaohuang main_size bold">*{{ite.number}}</view>
						</view>
					</view>
					
				</view>
				<view class="flexright margin_top">
					<view class="xiaohui main_size">共计{{item.goods_num}}件商品 合计</view>
					<view class="xiaohuang main_size">{{item.total_price}}</view>
				</view>
				<!-- 订单状态:1=待支付,3=待核销,6=已完成,7=已取消-->
				<view class="flexright margin_top">
					<view class="listbtnhui margin_left" v-if="item.state==1 || item.state==3" @click.stop="currentid=item.id;showModal('是否确认取消订单？')">取消订单</view>
					<view class="listbtnlan margin_left" v-if="item.state==3">查看券码</view>
					<view class="listbtnlan margin_left" v-if="item.state==1" @click.stop="pay(item)">立即支付</view>
					<view class="listbtnhui margin_left" v-if="item.state==6 || item.state==7" @click.stop="currentid=item.id;showModal('是否确认删除当前订单？')">删除订单</view>
					
				</view>
			</view>
		</view>
		
		<moDal :message="modal" @modalSure="modalSure" @modalcancel="modalcancel"></moDal>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				tabsid: 0,
				tabs: [{
					id: 0,
					name: '全部',
				},{
					id: 1,
					name: '待支付',
				}, {
					id: 3,
					name: '待核销',
				}, {
					id: 6,
					name: '已完成'
				}],
				modal:{
					modalShow:false,
					title:"",
				},
				currentid:"",
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
					state: this.tabsid
				}
				let url = '/api/order/getorderlist'
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			showModal(val){
				this.modal.title = val
				this.modal.modalShow = true
			},
			modalSure(){
				if(this.modal.title=="是否确认取消订单？"){
					this.cancelorder()
				}else if(this.modal.title=="是否确认删除当前订单？"){
					this.delOrder()
				}
				this.modalcancel()
			},
			modalcancel(){
				this.modal.modalShow = false
			},
			cancelorder(){
				httpRequest.request('/api/order/cancelOrder', 'GET', {
					order_id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.init()
					}
				})
			},
			delOrder(){
				httpRequest.request('/api/order/delOrder', 'POST', {
					id: this.currentid,
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.init()
					}
				})
			},
			pay(item){
				let data = {
					pay_price:item.total_price,
					type:1,
					order_id:item.id
				}
				uni.navigateTo({
					url:"/pages_index/zhifu?msg="+encodeURIComponent(JSON.stringify(data))
				})
			},
			tabclick(e) {
				this.tabsid = e.id
				this.init()
			}
		}
	}
</script>

<style>

</style>
